using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace SunshineFarmWord
{
    public class PlantUI : MonoBehaviour
    {
        [field: SerializeField, Header("选择的种子UI节点")]
        private GameObject plantUINode;

        private PlayerStateMachine _playerStateMachine;
        void Awake()
        {
            //注册选择种子和取消选择种子的事件
            SystemObserverManage.Instance.InvokeEvent(GameObjEnumClass.EventNotifyEnum.SelectSeeds, OnClickSeed);
            SystemObserverManage.Instance.InvokeEvent(GameObjEnumClass.EventNotifyEnum.DeselectSeeds, OnClickCancel);
        }

        void Start()
        {
        }

        void Update()
        {
        }

        //注销
        void OnDestroy()
        {
            SystemObserverManage.Instance.RemoveEvent(GameObjEnumClass.EventNotifyEnum.SelectSeeds, OnClickSeed);
            SystemObserverManage.Instance.RemoveEvent(GameObjEnumClass.EventNotifyEnum.DeselectSeeds, OnClickCancel);
        }

        //开始选择种子时的事件
        public void OnClickSeed(object stateMachineObj)
        {
            _playerStateMachine = stateMachineObj as PlayerStateMachine;
            _playerStateMachine?.Player.PlayerInput.PlayerActions.Disable();
            //游戏暂停
            SystemTimeManage.Instance.PauseGameClock();
            ShowHide(true);
        }
        //取消选择种子时的事件
        public void OnClickCancel(object _)
        {
            _playerStateMachine?.Player.PlayerInput.PlayerActions.Enable();
            //游戏恢复
            SystemTimeManage.Instance.ResumeGameClock();
            ShowHide(false);
        }

        //显示隐藏
        public void ShowHide(bool isShow)
        {
            if (plantUINode.activeSelf != isShow) plantUINode.SetActive(isShow);
        }
    }
}
